// void, Obj me, Obj target

Unit tgt;
Unit this;
str class;
point pt;
ObjList ol;

Sleep(rand(100)+10);
this = me.AsUnit;
tgt = target.AsUnit;
class = tgt.class;
pt = tgt.posRH;

if (.IsValid) {// leave parry mode at new command
	.SetParryMode(false);
	
	if(.hero.IsValid){
		if(.hero.HasItem("irage_battle")){
			Sleep(rand(200)+10);
			.AddCommand(true, "engage");
			return;
		} else if(.hero.HasItem("irage_battle_stand")){
			Sleep(rand(200)+10);
			.AddCommand(true, "stand_position");
			return;
		}
	}
	
	if(.item_count > 0){
		Item item;
		
		item = .FindItem("Terrain bonus I");
		if(item.IsValid)
			.RemoveItemsOfType("Terrain bonus I");
		else {
			item = .FindItem("Terrain bonus II");
			if(item.IsValid)
				.RemoveItemsOfType("Terrain bonus II");
			else {
				item = .FindItem("Terrain bonus III");
				if(item.IsValid)
					.RemoveItemsOfType("Terrain bonus III");
				else {
					item = .FindItem("Terrain bonus IV");
					if(item.IsValid)
						.RemoveItemsOfType("Terrain bonus IV");
				}
			}
		}
	}
}

//pr("unit attack type"); 
while(!.Goto(pt, 0, 4000, true, 0))
{
        //pr("unit_type");
	if(tgt.IsAlive)
	{
		pt = tgt.posRH;
	}
	if(.DistTo(pt) < .sight*2/3)
	{
		if(!tgt.IsAlive)
		{
			ol = Intersect(ObjsInSight(this, class), EnemyObjs(.player, class)).GetObjList;
			if(ol.count > 0)
			{
				tgt = ol[0];
			}
		}
		if(tgt.IsAlive)
		{
			Sleep(rand(100)+100);
			.AddCommand(true, "engage_unit_type", tgt);
		} else
		{
			Sleep(rand(100)+100);
			.AddCommand(true, "engage");
		}
		return;
	}
}	
